﻿using System.Collections.Generic;
using System.ComponentModel;

namespace MeTool
{
    public static class ListHelper
    {
        /// <summary>
        /// 扩展方法. 根据当前数据生成并返回一个泛型 BindingList
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="theList"></param>
        /// <returns></returns>
        public static BindingList<T> ToBindingList<T>(this IList<T> list)
        {
            return new BindingList<T>(list);
        }

        /// <summary>
        /// 合并两个泛型 List. 去除 secondList 中重合的项
        /// </summary>
        /// <param name="firstList"></param>
        /// <param name="secondList"></param>
        /// <returns></returns>
        public static List<T> Merge<T>(this IEnumerable<T> firstList, IEnumerable<T> secondList)
        {
            var dList = new List<T>(firstList);
            foreach (var dItem in secondList) if (!dList.Contains(dItem)) dList.Add(dItem);
            return dList;
        }
    }
}
